package com.xiaoma.myaudience.biz.task;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.content.Context;

import com.xiaoma.myaudience.biz.util.Constant;
import com.xiaoma.myaudience.util.HttpUtils;
import com.xiaoma.myaudience.util.Logger;
import com.xiaoma.myaudience.util.model.ModelUtils;
import com.xiaoma.myaudience.util.task.BaseDataAsyncTask;

public class SendPhonecodeTask extends
		BaseDataAsyncTask<String, Void, String> {
	private final static String TAG = "SendPhonecodeTask";
	public SendPhonecodeTask(
			Context context,
			int what,
			DataAsyncCallback callback) {
		super(context, what, callback);
		// TODO Auto-generated constructor stub
	}
	@Override
	protected String doInBackground(String... params) {
		if(null==params){
			return null;
		}
		String phonenum = params[0];
		String result = null;
		Map<String,Object> returnjson = null;
        try {            
        	List<NameValuePair> values = new ArrayList<NameValuePair>();
        	values.add(new BasicNameValuePair("phone", phonenum));
        	values.add(new BasicNameValuePair("status", "2"));
        	JSONObject jsonObject = HttpUtils.getHttpJSONObjectResult(getHttpClient(), 
        			Constant.URL_SENDPHONENUM_PATH, values, HttpUtils.GET);
        	if (jsonObject != null) {
        		returnjson = ModelUtils.json2Map(jsonObject);
        		result = (String) returnjson.get("code");
			}
        } catch (Exception e) {
            Logger.e(TAG, "doInBackground error!!!", e);
        } finally {
            closeHttpClient();
        }
        
        return result;
	}

}
